package sioserver;

import java.io.IOException;
import java.net.ServerSocket;

/**
 * 辅助类ShutdownHookThread，在程序异常终止时，确保serversocket被关闭。
 * 
 * @athor Xinz
 *
 */
public class ShutdownHookThread extends Thread {

	private ServerSocket serverSocket;
	
	public ShutdownHookThread(ServerSocket serverSocket) {
		this.serverSocket = serverSocket;
	}
	
	@Override
	public void run() {
		try {
			serverSocket.close();
		}
		catch(IOException e) {
			e.printStackTrace();
		}
		finally {
			serverSocket = null;
		}
	}
}
